package com.ocom.payconfig.controller;

import com.ocom.common.constant.PayConfigUrl;
import com.ocom.common.entity.payconfig.EntityXfDeviceMealConfig;
import com.ocom.common.request.payconfig.ConsDeviceMealConfigVo;
import com.ocom.common.request.payconfig.SetConsDeviceMealConfigRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.payconfig.service.XfDeviceMealConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: TODO
 * @Author: 朱晖
 * @Date: 2023/2/3
 **/
@Slf4j
@RestController
public class ConsDeviceMealConfigController {


	@Autowired
	private  XfDeviceMealConfigService xfDeviceMealConfigService;

	@PostMapping(PayConfigUrl.Url_getConsDeviceMealConfig)
	public Result getConsDeviceMealConfig(Long comId,String deviceNo,Integer consType){
		SetConsDeviceMealConfigRequest  setConsDeviceMealConfigRequest =new SetConsDeviceMealConfigRequest();
		setConsDeviceMealConfigRequest.setComId(comId);
		setConsDeviceMealConfigRequest.setDeviceNo(deviceNo);
		setConsDeviceMealConfigRequest.setConsType(consType);
		List<EntityXfDeviceMealConfig> list =  xfDeviceMealConfigService.getConsDeviceMealConfig(comId,deviceNo,consType);
		if(list!=null && list.size()>0){
			for(EntityXfDeviceMealConfig entityXfDeviceMealConfig:list){
				ConsDeviceMealConfigVo consDeviceMealConfigVo=new ConsDeviceMealConfigVo();
				consDeviceMealConfigVo.setMealNo(entityXfDeviceMealConfig.getMealNo());
				consDeviceMealConfigVo.setMealMoney(entityXfDeviceMealConfig.getMealMoney());
				consDeviceMealConfigVo.setAccounts(entityXfDeviceMealConfig.getAccountIds());
				consDeviceMealConfigVo.setKeyMode(entityXfDeviceMealConfig.getKeyMode());
				consDeviceMealConfigVo.setVoucherMode(entityXfDeviceMealConfig.getVoucherMode());
				consDeviceMealConfigVo.setVoucherTypes(entityXfDeviceMealConfig.getVoucherTypes());
				setConsDeviceMealConfigRequest.getConfigList().add(consDeviceMealConfigVo);
			}
		}
		return ResultUtil.success(setConsDeviceMealConfigRequest);
	}

	@PostMapping(PayConfigUrl.Url_setConsDeviceMealConfig)
	public Result setConsDeviceMealConfig(@RequestBody SetConsDeviceMealConfigRequest request){
		xfDeviceMealConfigService.setConsDeviceMealConfig(request.getComId(),request);
		return ResultUtil.success();
	}

}
